package com.ics.cmsadmin.frame.interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登陆拦截器
 * Created by Administrator on 2017/7/28.
 */
@Component
public class BeforeLoginInterceptor extends HandlerInterceptorAdapter {
    protected static final Logger LOGGER = LoggerFactory.getLogger(BeforeLoginInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Headers", "authorization, Origin, X-Requested-With, Content-Type, Accept, LOGIN_TOKEN");
        response.setCharacterEncoding("UTF-8");
//        String requestURI = request.getRequestURI();
//        if (requestURI.startsWith(request.getContextPath() + "/dist/")){
//            response.sendRedirect(request.getContextPath() + "/dist/index.html");
//            return false;
//        }
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    }

}
